package web;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import domain.User;
import repository.UserDAO;

@WebServlet("/UserDate")
public class UserDate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UserDate() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<User> userList = new ArrayList<User>(); 
		
		UserDAO userdao = null;
		try {
			userdao = new UserDAO();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		ResultSet rs = userdao.query();
		try {
			while (rs.next()) {
				User user = new User();
				user.setUserName(rs.getString("用户名"));
				user.setPwd(rs.getString("密码"));
				user.setPhnumber(rs.getString("电话号码"));
				user.setAdamic(rs.getString("学院名称"));
				userList.add(user);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		request.setAttribute("userList", userList);
		request.getRequestDispatcher("PropertySco.jsp").forward(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
